///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// You can load dynamic lib on different os platform by it
///</describe>
/// <date>2021/1/31</date>
///***********************************************************************
#ifndef DllLoader_H
#define DllLoader_H

#include <time.h>
#include <atomic>
#include <string>
#include <fstream>
#include <iostream>
#include "boost/dll.hpp"
#include "boost/function.hpp"

namespace SystemTool
{
	class DllLoader
	{
	public:
		typedef boost::dll::shared_library ShareLibrary;

	public:
		// Construct the share lib
		DllLoader();

		// Destory the share lib
		~DllLoader();

	public:
		// Load the library
		bool Load(std::string strLibFullPath);

		// Unload the library
		void Unload();

		// Is load the library
		bool IsLoad();

		// Is have the function
		bool IsHasFunc(std::string strFuncName);

		// Get the inner library object so that you can use like auto f = MyObject()->get<void(int)>("add");
		ShareLibrary& GetInnerObject()
		{
			return GetShareLib();
		}

	private:
		// Get the ShareLib
		inline ShareLibrary& GetShareLib()
		{
			return m_ShareLib;
		}

		// Set the ShareLib
		inline void SetShareLib(ShareLibrary& myShareLib)
		{
			m_ShareLib = myShareLib;
		}

		// Get the Disposed
		inline bool GetDisposed() const
		{
			return m_bDisposed;
		}

		// Set the Disposed
		inline void SetDisposed(bool bDisposed)
		{
			m_bDisposed = bDisposed;
		}

	private:
		// Share library
		ShareLibrary m_ShareLib;
		
		// Share lib's full path
		std::string m_strShareLibPath;

		// Dispose status
		std::atomic<bool> m_bDisposed;
	};
}

#endif // DllLoader_H
